package baseTest;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Scanner;


public class Tree {
    public static void main(String[] args) {
            int L,M;
            int i,j;
            int sum=0;
            int s[]=new int [10001];
            Scanner scan=new Scanner(System.in);
            L=scan.nextInt();
            M=scan.nextInt();
            for(j=0;j<M;j++)
            {
                int a,b;
                a=scan.nextInt();
                b=scan.nextInt();
                for(i=a;i<=b;i++)
                    s[i]=1;
            }
            for(i=0;i<=L;i++)
            {

                if(s[i]==0)
                    sum++;
            }
            System.out.println(sum);
        }

    }
